package us.ajg0702.leaderboards.boards;

import org.bukkit.Bukkit;
import us.ajg0702.leaderboards.Main;
import us.ajg0702.leaderboards.cache.Cache;

import java.util.HashMap;

public class TopManager {
    private static TopManager instance;
    private final Main plugin;
    private final HashMap<String, HashMap<Integer, Long>> lastGet;
    private final HashMap<String, HashMap<Integer, StatEntry>> cache;
    private TopManager(Main pl) {
        this.lastGet = new HashMap<>();
        this.cache = new HashMap<>();
        this.plugin = pl;
    }

    public static TopManager getInstance() {
        return instance;
    }

    public static TopManager getInstance(Main pl) {
        if (instance == null) {
            instance = new TopManager(pl);
        }
        return instance;
    }

    public StatEntry getStat(int position, String board) {
        if (!this.cache.containsKey(board)) {
            this.cache.put(board, new HashMap<>());
        }
        if (!this.lastGet.containsKey(board)) {
            this.lastGet.put(board, new HashMap<>());
        }

        if (this.cache.get(board).containsKey(Integer.valueOf(position))) {
            if (System.currentTimeMillis() - ((Long) ((HashMap) this.lastGet.get(board)).get(Integer.valueOf(position))).longValue() > 5000L) {
                this.lastGet.get(board).put(Integer.valueOf(position), Long.valueOf(System.currentTimeMillis()));
                fetchPositionAsync(position, board);
            }
            return (StatEntry) ((HashMap) this.cache.get(board)).get(Integer.valueOf(position));
        }

        this.lastGet.get(board).put(Integer.valueOf(position), Long.valueOf(System.currentTimeMillis()));
        return fetchPosition(position, board);
    }

    private void fetchPositionAsync(int position, String board) {
        Bukkit.getScheduler().runTaskAsynchronously(this.plugin, () -> fetchPosition(position, board));
    }

    private StatEntry fetchPosition(int position, String board) {
        StatEntry te = Cache.getInstance().getStat(position, board);
        this.cache.get(board).put(Integer.valueOf(position), te);
        return te;
    }
}


*Location:D:\User\Xuan\Downloads\ajLeaderboards-1.3.3.jar\\us\ajg0702\leaderboards\boards\TopManager.class
 *Java compiler version:8(52.0)
         *JD-Core Version:1.1.3
